<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="用户手机" prop="mobile">
        <el-input
          v-model="queryParams.mobile"
          placeholder="请输入投诉用户手机"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="投诉类型" prop="reportReason">
        <el-select v-model="queryParams.reportReason" placeholder="请选择投诉类型" clearable
                   size="small">
          <el-option
            v-for="dict in reportReasonOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="投诉时间" prop="createTime">
        <el-date-picker clearable size="small" style="width: 200px"
                        v-model="queryParams.createTime"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="选择投诉时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="danger" icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
                   v-hasPermi="['complain:report:remove']">
          删除
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="list" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="举报用户手机" align="center" prop="mobile"/>
      <el-table-column label="举报用户微信" align="center" prop="wechat"/>
      <el-table-column label="被举报用户手机" align="center" prop="toMobile"/>
      <el-table-column label="被举报用户微信" align="center" prop="toWechat"/>
      <el-table-column label="举报原因" align="center" prop="reportReason"
                       :formatter="reportReasonFormat"/>
      <el-table-column label="图片(点击图片查看更多)" align="center" prop="imageIds">
        <template slot-scope="scope">
          <el-image
            v-show="scope.row.images!=null && scope.row.images.length > 0"
            style="width: 80px; height: 50px"
            :src="scope.row.images[0]"
            :preview-src-list="scope.row.images">
          </el-image>
          <span>{{scope.row.images.length}}张</span>
        </template>
      </el-table-column>
      <el-table-column label="补充描述" align="center" prop="describe"/>
      <el-table-column label="投诉时间" align="center" prop="lastupdateTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.lastupdateTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
                     v-hasPermi="['complain:report:remove']">
            删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="pageNum"
      :limit.sync="pageSize"
      @pagination="getList"/>

    <add-or-update v-show="open" @on-close="open=false" ref="addOrUpdate"></add-or-update>
  </div>
</template>

<script>
  import {
    listReport,
    getReport,
    delReport,
    exportReport
  } from '@/api/complain/report'
  import mixinViewModule from '@/mixins/view-module'
  import AddOrUpdate from './add-or-update'

  export default {
    name: 'Report',
    mixins: [mixinViewModule],
    components: { AddOrUpdate },
    data() {
      return {
        mixinViewModuleOptions: {
          getDetailsURL: getReport,// 查询详情实体
          getDataListURL: listReport, // 数据列表接口，API地址
          deleteURL: delReport, // 删除接口，API地址
          deleteIsBatchKey: 'id', // 删除接口，批量状态下由那个key进行标记操作？比如：pid，uid...
          exportURL: exportReport // 导出接口，API地址
        },
        // 遮罩层
        loading: true,
        // 显示搜索条件
        showSearch: true,
        // 弹出层标题
        title: '',
        // 是否显示弹出层
        open: false,
        // 举报原因字典
        reportReasonOptions: [],
        // 查询参数
        queryParams: {
          userId: null,
          createTime: null,
          orderByColumn: 't.create_time',
          isAsc: 'desc'
        }
      }

    },
    created() {
      this.getList()
      this.getDicts('complain_report_reason').then(response => {
        this.reportReasonOptions = response.data
      })
    },
    methods: {
      // 举报原因字典翻译
      reportReasonFormat(row, column) {
        return this.selectDictLabel(this.reportReasonOptions, row.reportReason)
      },
      //打开dislog前执行
      onOpenHandleDialog() {

      },
      //打开删除前执行
      onHandleDetails(data, type) {
        if (type == this.$formType.edit) {
          this.$refs.addOrUpdate.form = data.data
        }
      },
      //开始查询列表的时候
      onStartQuery() {

      },
      //开始重制查询前执行
      onResetQuery() {

      }
    }
  }
</script>
